<?php
use yii\helpers\Url;

$web = Url::base();
?>

<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall/cart.css"/>
<script>
    $(function() {
        var checked_number = 0;
        var input_checkbox = $(".listing .choice-checkbox");
        $("#all_checkbox").click(function() {
            if ($("#all_checkbox").is(':checked') == true) {
                input_checkbox.prop('checked', true);
            } else {
                $(".listing .choice-checkbox").prop('checked', false);
            }
        })
        input_checkbox.each(function(index) {
            $(this).click(function() {
                if ($(this).is(':checked') == false) {
                    $("#all_checkbox").prop('checked', false);
                }
                checked_number = 0;
                input_checkbox.each(function(index) {
                    if ($(this).is(':checked') == true) {
                        checked_number += 1;
                    }
                    if (checked_number == input_checkbox.length) {
                        $("#all_checkbox").prop('checked', true);
                    }
                });
            });
        });
    })
</script>

<?php
$data_count = 0;
$selected_data_count = 0;
$quantity_sum = 0;
if ($goods_list != null) {
    $data_count = count($goods_list);
    for ($i = 0; $i < count($goods_list); $i++) {
        $quantity_sum = $quantity_sum + $goods_list[$i]['quantity'];
        if ($goods_list[$i]['is_selected'] == 1) {
            $selected_data_count = $selected_data_count + 1;
        }
    }
}
?>

<div class="classify">
    <ul>
        <li class="btn1">
            <label class="checkbox fl">
                <input id="all_checkbox" class="choice-checkbox" type="checkbox" <?php if ($data_count == $selected_data_count) echo 'checked'; ?> onclick="allSelectedChange(this)">全选
            </label>
        </li>
        <li>共<span>（<?= $quantity_sum ?>）</span>件商品</li>
        <li>单价</li>
        <li>数量</li>
        <li>小计</li>
        <li>操作</li>
    </ul>
</div>
<?php
if ($goods_list != null) {
    for ($i = 0; $i < count($goods_list); $i++) {
        ?>
        <div class="listing">
            <label class="checkbox fl">
                <input type="checkbox" class="choice-checkbox"
                       id="<?= $goods_list[$i]['id'] ?>" <?php if ($goods_list[$i]['is_selected'] == 1) echo 'checked'; ?>
                       onclick="selectedChange('<?= $goods_list[$i]['id'] ?>')"></label>
            <div class="goods-img fl">
                <a href="javascript:void(0)"><img src="<?= $goods_list[$i]['goods_image'] ?>"/></a>
            </div>
            <div class="goods-name fl">
                <p><?= $goods_list[$i]['name'] ?> </p>
            </div>
            <div class="statistics">
                <ul>
                    <li><?= number_format($goods_list[$i]['selling_integral']) ?></li>
                    <li>
                        <div class="goods-number">
                            <div class="gw-num fl">
                                <span class="jian"
                                      onclick="onQuantityJian(this,'<?= $goods_list[$i]['id'] ?>')" style="<?php if($goods_list[$i]['quantity']>1) echo 'color:#8a8a8a'; ?>">-</span>
                                <input type="text" value="<?= $goods_list[$i]['quantity'] ?>" class="num"
                                       onblur="onQuantityUpdate(this,'<?= $goods_list[$i]['id'] ?>');"/>
                                <span class="add" onclick="onQuantityAdd(this,'<?= $goods_list[$i]['id'] ?>')">+</span>
                            </div>
                        </div>
                    </li>
                    <li><input class="hidden_selling_integral_sum" type="hidden"
                               value="<?= $goods_list[$i]['selling_integral_sum'] ?>"/>
                        <?= number_format($goods_list[$i]['selling_integral_sum']) ?></li>
                    <li><input type="button" value="删除" onclick="onRemoveGoods('<?= $goods_list[$i]['id'] ?>')"/></li>
                </ul>
            </div>
        </div>
        <?php
    }
}
?>
